import inherits from 'inherits';

import PropertiesActivator from 'bpmn-js-properties-panel/lib/PropertiesActivator';

// Require all properties you need from existing providers.
// In this case all available bpmn relevant properties without camunda extensions.
import processProps from 'bpmn-js-properties-panel/lib/provider/bpmn/parts/ProcessProps';
import idProps from 'bpmn-js-properties-panel/lib/provider/bpmn/parts/IdProps';
import nameProps from 'bpmn-js-properties-panel/lib/provider/bpmn/parts/NameProps';

import candidateProps from './parts/CandidateProps';
import formProps from './parts/FormProps';

function createGeneralTabGroups(element, bpmnFactory, canvas, translate) {
  const generalGroup = {
    id: 'general',
    label: translate('General'),
    entries: []
  };
  idProps(generalGroup, element, translate);
  nameProps(generalGroup, element, bpmnFactory, canvas, translate);
  processProps(generalGroup, element, translate);

  return [
    generalGroup
  ];
}

function createCandidateTabGroups(element, translate) {
  const candidateGroup = {
    id: 'candidate',
    label: translate('Candidate'),
    entries: []
  };

  // Add the spell props to the black magic group.
  candidateProps(candidateGroup, element, translate);

  return [
    candidateGroup
  ];
}

function createFormTabGroups(element, translate) {
  const formGroup = {
    id: 'form',
    label: translate('Form'),
    entries: []
  };

  // Add the spell props to the black magic group.
  formProps(formGroup, element, translate);

  return [
    formGroup
  ];
}

export default function FlowablePropertiesProvider(
  eventBus, bpmnFactory, canvas,
  elementRegistry, translate) {

  PropertiesActivator.call(this, eventBus);

  this.getTabs = function (element) {

    const generalTab = {
      id: 'general',
      label: translate('General'),
      groups: createGeneralTabGroups(element, bpmnFactory, canvas, translate)
    };

    const candidateTab = {
      id: 'candidate',
      label: translate('Candidate'),
      groups: createCandidateTabGroups(element, translate)
    };

    const formTab = {
      id: 'form',
      label: translate('Form'),
      groups: createFormTabGroups(element, translate)
    };

    return [
      generalTab,
      candidateTab,
      formTab
    ];
  };
}

inherits(FlowablePropertiesProvider, PropertiesActivator);
